use "americas_barometer"
gen female = 1 if sex==2
replace female = 0 if sex==1
gen colour = colorr if colorr<15
drop if pais==40|pais==41
gen white = 1 if etid==1
replace white = 0 if etid!=1
gen mixed = 1 if etid==2|etid==5
replace mixed = 0 if etid!=2 & etid!=5
gen native = 1 if etid==3
replace native = 0 if etid!=3
gen black = 1 if etid==4
replace black = 0 if etid!=4
rename ed education
rename ed2 mother_education
rename q2 age
rename q10new income_bucket
gen colour_bin = 1 if colour==1|colour==2|colour==3|colour==4
replace colour_bin = 2 if colour==5|colour==6|colour==7
replace colour_bin = 3 if colour==8|colour==9|colour==10|colour==11
gen urban = 1 if ur==1
replace urban = 0 if ur==2
gen size = 1 if tamano==5
replace size = 2 if tamano==4
replace size = 3 if tamano==3
replace size = 4 if tamano==2
replace size = 5 if tamano==1
rename pais country
gen central_america =1 if country==1|country==2|country==3|country==4|country==5|country==6|country==7
replace central_america =0 if country!=1&country!=2&country!=3&country!=4&country!=5&country!=6&country!=7
gen caribbean = 1 if country==21|country==22|country==23|country==25|country==28|country==29
replace caribbean = 0 if country!=21&country!=22&country!=23&country!=25&country!=28&country!=29
gen south_america = 1 if country==8|country==9|country==10|country==11|country==12|country==13|country==14|country==15|country==16|country==17|country==24|country==26|country==27
replace south_america = 0 if country!=8&country!=9&country!=10&country!=11&country!=12&country!=13&country!=14&country!=15&country!=16&country!=17&country!=24&country!=26&country!=27
gen region = 1 if caribbean==1
replace region = 2 if central_america==1
replace region = 3 if south_america==1
xtset country
*Results for Table 1
reg education colour female age black mixed native mother_education urban size i.country if caribbean==1, r
reg income_bucket colour education female age black mixed native mother_education urban size i.country if caribbean==1, r
reg education colour female age black mixed native mother_education urban size i.country if south_america==1, r
reg income_bucket colour education female age black mixed native mother_education urban size i.country if south_america==1,r
*Graph for Figure 2
binscatter education colour if(caribbean==1|country==15)&(white==1|mixed==1|black==1), by(mixed) ylab(, nogrid) xlab(, nogrid)
*Graphs for Figure 3
binscatter education colour, controls(female age etid mother_education urban size) by(region) ylab(, nogrid) xlab(, nogrid)
binscatter income_bucket colour, controls(education female age etid mother_education urban size) by(region) ylab(, nogrid) xlab(, nogrid)
*Results for Appendix Table D.3
reg education colour_bin female age black mixed native mother_education urban size i.country if caribbean==1, r
*Results for Appendix Table D.5
reg income_bucket colour education female age black mixed native mother_education urban size i.country, r
reg income_bucket colour education female age black mixed native mother_education urban size i.country if caribbean==1, r
reg income_bucket colour education female age black mixed native mother_education urban size if country==15,r
